Summary

Episodes [TABS]

Season 1

Episode 1: Peter applies for welfare to support his family after losing his job. He receives a check for $150,000 due to a misplaced decimal point, and uses it to buy lavish presents for his family. Lois is upset when she finds out after receiving a new welfare check in the mail; Peter attempts to make her happy by dropping his surplus money out of a blimp above Super Bowl XXXIII with the help of Brian. Both are arrested by security guards and prosecuted for welfare fraud. At the courthouse, Lois pleads with the judge not to imprison Peter; Stewie, grudgingly coming to realize his dependence on his parents, influences the judge to reconsider the sentence.

Episode 2: Peter has become addicted to television. While driving Meg home, he is distracted by a show he wanted to watch on a television in a nearby house, and crashes into the city’s cable transmitter, cutting reception for the entire town of Quahog. Peter panics and steals the transmitter and convinces Meg to take blame for the outage. Stewie steals the satellite dish in a plan to create a weather control device. Suffering withdrawal syndrome from lack of television, Peter straps a cardboard cutout to himself, making it appear as though the world is a television program. Meg confesses that her father actually was to blame for the cable outage, causing the town to turn against him; he is saved when Lois gives a heartfelt speech to the community. Inspired, Peter brings the family to various outdoor activities, quickly exhausting them; he then goes off with William Shatner. Meanwhile, Stewie’s weather machine creates a rainstorm; while Meg is practicing driving, the storm causes her to accidentally hit Shatner and Peter, killing Shatner and hospitalizing Peter. As her father recovers in a full-body cast, he is forced to watch television, causing him to become addicted once again.

Episode 3: Peter accidentally loses the reservation for Stewie’s first birthday party at a local restaurant, and must create a new party. Meanwhile, Stewie misinterprets “birthday”, assuming that the mysterious Man in White who delivered him as an infant will return to force him back into Lois’ womb. Peter fails to put together a party in time for Stewie’s birthday, and reroutes a circus parade into the Griffins’ backyard. He gives Meg permission to go to a “party” at her friend’s house, not realizing that it is a cult meeting where the attendees will commit mass suicide by drinking poisoned fruit punch. Peter retrieves Meg before the cult members drink the punch. The cult leader notices that Meg did not drink; he puts on his white robe and goes to the Griffins’ house. Stewie traps and kills the cult leader, thinking he is the Man in White.

Episode 4: Stewie has begun teething; Lois explains to him that the pain will pass with time, so he decides to build a time machine. Lois asks Peter to take Chris to a soccer game; there, Peter punches a pregnant woman and is put under house arrest. Peter decides to open a bar in his basement so that his friends will come to visit; it becomes a hot spot and Lois becomes upset until she sings at the bar. Peter becomes jealous and has his friends’ wives to drag them out of the bar. A cigarette starts a fire; when Peter and Lois become aware of it and attempt to escape, Stewie’s time machine takes everyone back to the point when Lois asks Peter to take Chris to the game. This time, Peter trips over the time machine and destroys it.

Episode 5: After Peter injures the Happy-Go-Lucky Toy Factory’s new employee Guillermo during softball practice, he is forced by his boss Mr. Weed to find a replacement for the upcoming softball game. Meanwhile, Lois meets the Griffin family’s new neighbors, the Swansons. Peter is initially annoyed by Joe Swanson and has no interest in becoming his friend, but convinces Joe to play for the softball team once Lois mentions that he played baseball in college. Next morning at the game, Peter is surprised to learn that Joe is wheelchair-bound. Joe’s experience helps the team win. Peter becomes jealous of Joe and tries to become a hero by stopping a robbery; he ends up as a hostage until Joe convinces the robbers to surrender. Peter is disappointed, but his family tells him that he is their hero.

Episode 6: Chris is ejected from the Youth Scouts (Family Guy’s version of the Boy Scouts) when he runs over the troop leader at the Soap Box Derby. Although Chris dislikes scouts and prefers drawing, he fears telling Peter. When Peter finds out, he drives the family to the scout headquarters in Manhattan to get Chris readmitted. On a rest stop at a Native American casino, Lois becomes a gambling addict and loses the family car. Since each Native American receives a share of the casino profits, Peter pretends to be a Native American, and he is sent on a vision quest to prove his heritage. Chris accompanies Peter to explain that he only likes drawing. Delirious from hunger, Peter begins talking to anthropomorphic trees and has a vision of his spiritual guide, the Fonz. Peter recognizes his son’s talent for drawing; they return to the casino and reclaim the car.

Episode 7: Quahog is in the grip of an unusual heat wave. The Griffins ask Brian to enter a dog show, offering a top prize of $500, so they are able to buy air conditioning. Brian performs his tricks at the show; Peter asks Brian to beg for a treat, but Brian finds it demeaning and exits quickly. On the way home, Peter and Brian argue until Brian exits the car; the police give Brian a ticket for violating the local leash law. Another debate ensues and Peter mentions that he found Brian as a stray dog. Angry that Peter had brought that up, Brian leaves the house, whereupon he is badly treated by the community and must sleep at a bus stop. Peter purchases a new cat which turns out to be abusive, so the Griffins abandon it and search for Brian. By the time Peter decides to apologize to Brian, he has been taken away by the police and awaits his death sentence. Brian begins to plead his case, but is interrupted when the court decides “it is stupid” to listen to a dog. As he is about to be dismissed, Peter steps in and delivers a last-ditch emotional appeal on his behalf. The city council members hearing the case are not on Brian’s side, but Peter promises to give them $20 each, convincing them to free Brian. The charges against Brian are dropped and the town shows him new respect.

[reference] (https://en.wikipedia.org/wiki/Family_Guy_(season_1))

Season 2

Episode 1: One of Lois’ relatives, Marguerite Griffin dies, leaving Lois and the rest of the family her posh summer mansion in a will. However, when Peter becomes convinced that he is rich and ultimately bids $100 million at a charity auction, he attempts to convince the landowners his house is valuable enough to trade instead. After several futile attempts to “prove” that Cherrywood Manor has enough historical value to cover the bid, Peter makes up with Lois and uncovers a set of hidden photographs which show several prominent American figures (including Abraham Lincoln, Robert E. Lee, and Ulysses S. Grant) at Cherrywood Manor, which was a brothel at the time. This discovery allows Peter to buy back his home after selling the pictures to the tabloids. Afterwards, Peter decides that he does not care what Lois’ relatives think of him, since they were nothing more than “a bunch of pimps and whores”.

Episode 2: Peter’s devoutly religious, recently retired father Francis (Charles Durning) comes to visit, though he is intolerant of the others and makes life miserable for them; nevertheless, Peter tries to bond with him, since he had always been neglectful of his son. When all else fails, Peter resorts to kidnapping the Pope by taking the place of his regular driver to settle their conflict. He then brings the Pope back to his house, where the pope attempts to mediate his problems. Afterwards, Peter reconciles with Francis, who is hired for the job of working as the Pope’s security guard during his tour of the United States, pushing down people who are not allowed to be near the Pope and those who are allowed to be near the Pope, but are in his way, including Fox personnel, much to the Pope’s dismay. At the end of the episode, Peter’s mom shows up at the door and wishes to live with the family, prompting them to flee the house in an escape pod.

Episode 3: After a man in a chicken suit warns Peter that the world will end because of Y2K, Peter locks his family up in their basement on December 31, 1999. A nuclear holocaust then occurs, destroying much of the world and mutating, injuring, and killing many of the citizens of Quahog. The family then travel with the surviving citizens of Quahog to Natick, in hopes that the Twinkie factory survived; during the process, Stewie is exposed to the radiation and mutates into an octopus. However, upon their arrival, they find the factory to be deserted, and must survive alongside the citizens of the city in Natick (dubbed “New Quahog”). Peter is elected head of the town, but makes several fatal mistakes and is chased out of “New Quahog” alongside his family by an angry mob, singing “Left foot, right foot” the whole way out. The episode ends with a live action sequence involving Pamela Barnes Ewing waking up to find her husband Bobby in the shower. She tells him about the episode, which was a dream, thus retconning the entire episode, a parody of the Dallas episode “Blast from the Past”.

Episode 4: Stewie is blamed for urinating all over the house; however, it is actually Brian who is responsible; after urinating on the carpet once more overnight, Stewie is blamed. The next morning, Peter decides to potty train Stewie, with little success. When the family goes to the local supermarket to buy groceries, Brian urinates when they are at the checkout line, revealing to the family that Stewie is innocent. The family attempts to counsel Brian with therapy, where Brian’s psychiatrist Dr. Kaplan believes that he is having a mid-life crisis. Brian attempts to entertain himself by exploring the world, but upon returning home, Stewie gets revenge on Brian and frames him by urinating all over the living room. Brian is falsely accused and the family return him to Dr. Kaplan to find the true cause. After revealing that his most recent accident happened after watching Lois and Peter engaging in a water fight on the car, Dr. Kaplan informs Brian that he is most likely in love with Lois. After discussing the situation, both agree to remain friends. Afterwards, Brian decides to live life to the fullest by golfing with Peter on the local golf course.

Episode 5: The neighbors fight over a trophy won for the best parade float, and when it ends up getting stolen, everyone in town becomes a prime suspect. Meanwhile, Meg takes a job as a waitress at a pancake restaurant to earn money for a Prada bag, and claims that Stewie is her crack-addicted son for sympathy tips.

Episode 6: Peter gets out of paying a hefty hospital bill by declaring that he’s dead, only to get a surprise visit from Death himself. However, Death injures himself while chasing Peter and is unable to do his job, which makes everyone on Earth immortal, so Peter must stand in as the new Grim Reaper.

Episode 7: Lois is appointed the director of Quahog’s theatre company after the former director dies and attempts to produce The King and I. She appoints Peter as the producer to keep him out of her way, but his plans to recreate the play send him on a power trip that replaces her as the show’s director.

Episode 8: After telling a sexist joke at work, Peter is forced to go to a women’s retreat camp and comes back acting sensitive and effeminate. Lois and the others become greatly disturbed by his new attitude, and when his condition worsens, they do everything in their power to restore his manhood.

Episode 9: When Peter and Chris’ favorite TV show is cancelled, Peter pretends Chris is terminally ill and tells the “Grant-A-Dream Foundation” that his “final wish” is to get the show back on the air. When Chris does not die, however, Peter goes too far and declares himself to be a healer, starting his own religion.

Episode 10: Lois runs for President of the Quahog School Board, but Peter runs against her so he can save the job of his favorite teacher, smearing Lois’ image and winning by a landslide. But things take a turn for the worse when Chris is caught with pornography in school, so Peter must set all things right.

Episode 11: Peter begins to fear that his name will be forgotten, and strives to start a legacy of his own. When he sells a painting Chris gave him to an art gallery, Peter discovers that he can use Chris’ talents to fulfill this dream, taking the family to New York to see Chris become famous.

Episode 12: After being embarrassed by her family during her slumber party, Meg brings them on a daytime talk show out of revenge, where a TV producer turns the Griffins’ dysfunctional life into a reality show. Things go awry and Meg abandons everyone while the family slowly becomes replaced on the show.

Episode 13: Brian volunteers to bring Stewie home from his grandparents’ house in California, but the two miss their plane and must travel on foot for a cross-country journey back home. Meanwhile, Peter becomes addicted to watching a collection of marriage counseling videos hosted by a porn star.

Episode 14: Peter goes undercover as a high school student to kick youths off the habit of toad licking, making him extremely popular in Meg’s school. Meg asks her dad out to the upcoming school dance in the hopes of becoming popular herself, but Peter chooses to go out with popular Connie D’Amico instead.

Episode 15: Stewie is sent off to daycare to learn social skills where he falls in love with a girl named Janet. Meanwhile, Lois begins wishing that her life were more exciting, so she gets a job as a flight attendant at Peter’s request, who exploits Lois’ job position as a means to get free travel for himself.

Episode 16: Peter befriends a mob boss’s nephew, Big Fat Paulie, while paying off a debt. But when he says that Lois does not want them to hang out anymore, Paulie misinterprets the situation and thinks that Peter wants him to kill her so they can still be friends, so Peter must find a way to call off the hit.

Episode 17: Chris becomes insecure about his weight and goes on a diet, but Peter opts for plastic surgery and ends up getting it himself. Now thin and handsome, Peter becomes swayed by the special treatment he receives from people he comes across, while Lois, in spite of her morals, finds that she can not resist him. Meanwhile, Stewie starts overeating to taunt Chris, but ends up becoming obese.

Episode 18: While confronting the mayor about zoning issues around his house, Peter discovers that his house is not anywhere on the map, prompting him to secede his house from the rest of the United States, creating the country “Petoria”. His country gains no respect, so he invades the U.S. and annexes Joe’s pool.

Episode 19: Meg signs up for the high school newspaper club as Brown University’s academic requirement, but Peter replaces her original article with one about Luke Perry’s supposed homosexuality. This lands Meg in hot legal water with Perry, so Peter decides to “prove” that the actor is gay.

Episode 20: Peter wins a tour of a magical brewery owned by Pawtucket Pat (à la Charlie and the Chocolate Factory), while Lois desperately searches for a talented piano player to beat her rival at an upcoming talent competition, finding one in the form of her husband, who can only play professionally when he’s drunk.

Episode 21: Peter thinks his son lacks responsibility, so he gets him a job at a golf course. However, when he discovers that Cleveland’s son has the potential to become a pro golf player, he forsakes Chris to train the hyperactive Cleveland Jr. Discouraged, Chris finds a new father figure in Quagmire.

[reference] (https://en.wikipedia.org/wiki/Family_Guy_(season_2))

Season 3

Season 5

Season 6

Season 7

Season 8

Season 9

Season 10

Season 12

Libraries

library(tidyverse)
library(forcats)
theme_set(theme_minimal())
library(tidytext)
library(ggpubr)
library(topicmodels)

Exploratory Data Analysis

Data

# Load Data
family_raw <- read_csv("Data/Family_guy_dialog.csv")

# Feature processing & cleaing
family <- family_raw %>% 
  mutate(index = row_number()) %>% 
  select(index, season = seasons, character, dialog) %>% 
  mutate(season = str_replace(season, "season", "") %>% as.integer %>% as.factor) %>% 
  filter(character != "Maids and Butlers M&B") %>% 
  filter(character != "Quagmire") %>% 
  filter(character != "Cleveland")

# Visual
family %>% 
  group_by(season) %>% 
  slice_head(n = 3) %>%  
  knitr::kable(caption = "Family Guy: Data")
Family Guy: Data
index season character dialog
1 1 Stewie Damn you, vile woman! Youve impeded my work since the day I escaped from your wretched womb.
2 1 Stewie Hello, Mother.
3 1 Lois Well, hi, there, sweetie!
47 2 Lois Your Holiness, this is such an honor! Please, go into the living room, and make yourself at home!
48 2 Peter Nooooo! runs over to Trix rabbit and smacks Trix out of hand Silly rabbit, Trix are for kids. Damn longears trying to take Easter away from Jesus! to Chicken Man Im sorry, what were you saying?
49 2 Peter Randy Newman?
176 3 Peter A degenerate, am I? Well, you are a festisio! See? I can make up words too, sister.
177 3 Brian Hey, yknow what might be a thrill for you guys?
178 3 Chris Ooh! Ooh! Eating a pebble!
286 4 Peter Everybody, Ive got bad news. Weve been cancelled.
287 4 Lois Oh, no! Peter, how could they do that?
288 4 Peter Well, unfortunately, Lois, theres just no more room on the schedule. Weve just got to accept the fact that Fox has to make room for te
435 5 Peter I want some ice cream.
436 5 Peter I hate you! I hate you! I want my mommy!
439 5 Peter It’s alright. We’ll just move the party to the skating rink. Who’s sober enough to drive? nobody answers Uh, okay, who’s drunk, but that special kind of drunk where you’re a better driver because you know you’re drunk? You know, the kind of drunk where you probably shouldn’t drive, but you do anyway because, I mean, come on, you got to get your car home. Right? I mean, I mean, what do they expect me to do, take a bus? Is that what they want? For me to take a bus? Well, screw that! You take a bus.
575 6 Stewie That is fantastic! Terrific work! So, no weaknesses at all?
576 6 Chris Is it a fast ship?
577 6 Brian makes Chewbacca’s trademark gargling roar for a second, then spits out water in a nearby sink Always gargle before a take-off. Wocka-wocka! All right, let’s go.
663 7 Peter Brian, can I see that paper for a sec? Brian hands him the paper Huh, that’s odd. I thought that would be big news.
664 7 Brian You thought what would be big news?
665 7 Peter Well, there seems to be an absence of a certain ornithological piece. A headline regarding mass awareness of a certain avian variety.
743 8 Brian What the hell? What’s happened to us?
744 8 Stewie I don’t know, but suddenly I feel all sweet and warm and fuzzy. It seems we’re in a universe where everything is drawn by Disney.
745 8 Brian Look! There’s our house!
860 9 Stewie to Brian She doesn’t know what “mister” means.
861 9 Stewie Oh, my God, seriously.
862 9 Stewie after Stephanie is killed I can’t help but feel this would be sadder if she wasn’t so heavy.
982 10 Peter Your old boyfriend? The one with the penis?
983 10 Peter Shirts off! I want to see who’s got bigger pecs. tears off his shirt
984 10 Lois Peter!
1150 12 Peter to Lois I want you on my team for everything… except for sports.
1151 12 Stewie Ah! Friendly fire!
1153 12 Chris Why are your nipples poking into me?!
# color palette
peter <- "#2A6431"
lois <- "#F8784E"
stewie <- "#EB0C42"
brian <- "#E1E0DE"
chris <- "#0576C2"
meg <- "#E06EAA"

family_guy_Palette <- c(brian,chris,lois,meg,peter,stewie)

Counts

# EDA
family %>% 
  count(season, character) %>% 
  ggplot(aes(fct_reorder(character, n), n, fill = character)) + 
  geom_col(show.legend = FALSE, alpha = 0.4) +
  geom_label(aes(label = n), size = 3, color = "white") +
  facet_wrap(~season, scales = "free_x", nrow = 3) +
  coord_flip() +
  labs(
    title = "What is the Total Line Count by Character/Season ?"
  ) +
  theme(
    plot.title = element_text(face = "bold", color = "dodgerblue", hjust = 0.5, size = 25),
    plot.subtitle = element_text(color = "darkgoldenrod", hjust = 0.5, size = 15),
    axis.title = element_blank(),
    axis.text.y = element_text(face = "bold"),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "darkgoldenrod"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = family_guy_Palette)

NOTE (Count): Peter had the most lines for the majority of the seasons. However for seasons 8 and 9 the focus shift to Stewie and Brian.

Term Frequency [TABS]

# Stop Words
stops_Family <- 
  bind_rows(stop_words,
            tibble(
              word = c("gonna","uh","im","dont","youre","ive","wanna","hey", "yeah", "um"),
              lexicon = "CUSTOM")
  )
# Bag of Words
family_tidy <- family %>% 
  unnest_tokens(word, dialog) %>% 
  anti_join(stops_Family)

# Term Frequency
family_tf <- family_tidy %>% 
  count(word) %>% 
  arrange(-n)

family_tf_Character <- family_tidy %>% 
  group_by(character) %>%
  count(word) 

family_tf_Season <- family_tidy %>% 
  group_by(season) %>%
  count(word) 
family_tf %>% 
  top_n(25, n) %>% 
  ggplot(aes(n, fct_reorder(word,n))) +
  geom_col(fill = "gray", alpha = 0.5) +
  geom_label(aes(label = n), fill = "white") +
  labs(
    title = "What are the Top Words used throughout the Series ?",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(hjust = 0.5, size = 25, face = "bold", color = "dodgerblue"),
    axis.text.y = element_text(face = "bold", size = 10, color = "gray35"),
    axis.text.x = element_blank()
  )

By Character

# Top Words (Character)
family_tidy %>% 
  group_by(character) %>%
  count(word) %>% 
  arrange(-n) %>% 
  top_n(5, n) %>% 
  ggplot(aes(n, fct_reorder(word,n), fill = character)) +
  geom_col(show.legend = FALSE, alpha = 0.4) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~character, scales = "free") +
  labs(title = "What are the Top Words each charcter uses ?",
       x = NULL, y = NULL) +
  theme(
    plot.title = element_text(face = "bold", color = "dodgerblue", hjust = 0.5, size = 25),
    axis.title = element_blank(),
    axis.text.y = element_text(face = "bold"),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = family_guy_Palette)

NOTE (Term Frequecy): Based on the Term Frequency

  • Most of the characters are talking the Peter the most (Lois, Brain, Quagmire).

  • Peter and Lois talks to each other the most.

  • Brian talks to Peter and Stewie the most.

  • Stewie talks to Brian the most.

  • Chris and Meg talks to each other the most.

  • Meg talks to Chris the most.

By Season

# Top Words (Season 1-6)
gg_tf_Season_1_6 <- family_tidy %>% 
  filter(season %in% 1:6) %>% 
  group_by(character) %>%
  count(word) %>% 
  arrange(-n) %>% 
  top_n(4, n) %>% 
  ggplot(aes(n, fct_reorder(word,n), fill = character)) +
  geom_col(show.legend = FALSE, alpha = 0.4) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~character, scales = "free") +
  labs(
    subtitle = "Season: 1-6",
    x = NULL, y = NULL
  ) +
 theme(
    plot.title = element_text(face = "bold", color = "dodgerblue", hjust = 0.5, size = 25),
    plot.subtitle = element_text(color = "darkgoldenrod", hjust = 0.5, size = 15),
    axis.text.y = element_text(face = "bold"),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = family_guy_Palette)


# Top Words (Season 7-12)
gg_tf_Season_7_12 <- family_tidy %>% 
  filter(season %in% 7:12) %>% 
  group_by(character) %>%
  count(word) %>% 
  arrange(-n) %>% 
  top_n(5, n) %>% 
  ggplot(aes(n, fct_reorder(word,n), fill = character)) +
  geom_col(show.legend = FALSE, alpha = 0.4) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~character, scales = "free") +
  labs(
    subtitle = "Season: 7-12",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold", color = "#2A2A57", hjust = 0.5, size = 25),
    plot.subtitle = element_text(color = "darkgoldenrod", hjust = 0.5, size = 15),
    axis.text.y = element_text(face = "bold"),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = family_guy_Palette)
# Visual
ggAR_tf_Season <- ggarrange(gg_tf_Season_1_6, gg_tf_Season_7_12, nrow = 1)
ggAR_tf_Season %>% 
  annotate_figure(top = text_grob("What are the Top Words each character uses by Season ?",
                                  size = 25, face = "bold", color = "dodgerblue"))

NOTE (Term Frequency): Based on teh Term Frequency by Season

Season 1-6

  • The majority of the dialogue is between Peter and Lois

  • Brain also refers to Peter frequently.

  • Stewie refers to Brian Frequently

Season 7-12

  • The majority of the dialogue is spread betweeen Peter and Lois and Stewie and Brian.

  • Brian talks to Stewie more during the back half of the Series as opposed to Peter.

  • Quagmire gets more airtime consisting of him talking to Peter.

  • Chris and Meg also gets more airtime talking to each other

Bigram

# Bigram
family_bigram <- family %>% 
  unnest_tokens(bigram, dialog,
                token = "ngrams",
                n = 2)
family_bigram_clean_seperate <- family_bigram %>% 
  separate(bigram, c("word1","word2"), sep = " ") %>% 
  filter(!word1 %in% stops_Family$word) %>% 
  filter(!word2 %in% stops_Family$word)

family_bigram_clean_unite <- 
  family_bigram_clean_seperate %>% 
  unite(bigram, word1, word2, sep = " ") %>% 
  filter(bigram != "NA NA")

family_bigram_clean_unite %>% count(bigram) %>% arrange(-n) %>% top_n(15, n) %>% 
  knitr::kable(caption = "Top Bigrams")
Top Bigrams
bigram n
unga bunga 9
meg meg 6
bam bam 5
brian brian 4
bunga unga 4
cool hwhip 4
damn dials 4
fucking car 4
holy crap 4
ice cream 4
lois damn 4
peter griffin 4
care bear 3
careful careful 3
chris honey 3
family circus 3
giggity giggity 3
james woods 3
music video 3
olive juice 3
trap jaw 3
whoa whoa 3
# Top Bigram: Popular Words (Season)
family_bigram_clean_unite %>% 
  group_by(season) %>%
  count(bigram) %>% 
  arrange(-n) %>% 
  top_n(2, n) %>% 
  ggplot(aes(n, fct_reorder(bigram,n), fill = "blue")) +
  geom_col(show.legend = FALSE, alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~season, scales = "free") +
  labs(title = "What are the Top Bigrams by Season ?") +
  theme(
    plot.title = element_text(face = "bold", color = "dodgerblue", hjust = 0.3, size = 20),
    axis.title = element_blank(),
    axis.text.y = element_text(face = "bold"),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "darkgoldenrod"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = family_guy_Palette)

# Top Bigram: (Character)
family_bigram_clean_unite %>% 
  group_by(character) %>%
  count(bigram) %>% 
  arrange(-n) %>% 
  top_n(3, n) %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(bigram,n), fill = character)) +
  geom_col(show.legend = FALSE, alpha = 0.4) +
  geom_label(aes(label = n)) +
  facet_wrap(~character, scales = "free") +
  labs(
    title = "What are the Top Bigrams by Character ?",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold", color = "dodgerblue", hjust = 0.5, size = 20),
    axis.title = element_blank(),
    axis.text.y = element_text(face = "bold"),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "gray35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = family_guy_Palette)

family_bigram_clean_seperate %>% 
  filter(word1 == "peter") %>% 
  group_by(character) %>% 
  count(word1, word2) %>% 
  unite(bigram, word1, word2, sep = " ") %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(bigram,n), fill = character)) +
  geom_col(show.legend = FALSE) +
  facet_wrap(~character, scales = "free") +
  labs(title = "Top Bigram") +
  theme(
    plot.title = element_text(face = "bold", color = "#2A2A57", hjust = 0.3, size = 20),
    axis.title = element_blank(),
    axis.text.y = element_text(face = "bold")
  ) +
  scale_fill_manual(values = family_guy_Palette)

family_bigram_clean_seperate %>% 
  filter(word2 == "peter") %>% 
  group_by(character) %>% 
  count(word1, word2) %>% 
  unite(bigram, word1, word2, sep = " ") %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(bigram,n), fill = character)) +
  geom_col(show.legend = FALSE) +
  facet_wrap(~character, scales = "free") +
  labs(title = "Top Bigram") +
  theme(
    plot.title = element_text(face = "bold", color = "#2A2A57", hjust = 0.3, size = 20),
    axis.title = element_blank(),
    axis.text.y = element_text(face = "bold")
  ) +
  scale_fill_manual(values = family_guy_Palette)

family_bigram_clean_seperate %>% 
  filter(word1 == "damn") %>% 
  group_by(character) %>% 
  count(word1, word2) %>% 
  unite(bigram, word1, word2, sep = " ") %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(bigram,n), fill = character)) +
  geom_col(show.legend = FALSE) +
  facet_wrap(~character, scales = "free") +
  labs(title = "Top Bigram") +
  theme(
    plot.title = element_text(face = "bold", color = "#2A2A57", hjust = 0.3, size = 20),
    axis.title = element_blank(),
    axis.text.y = element_text(face = "bold")
  ) +
  scale_fill_manual(values = family_guy_Palette)

family_bigram_clean_seperate %>% 
  filter(word2 == "damn") %>% 
  group_by(character) %>% 
  count(word1, word2) %>% 
  unite(bigram, word1, word2, sep = " ") %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(bigram,n), fill = character)) +
  geom_col(show.legend = FALSE) +
  facet_wrap(~character, scales = "free") +
  labs(title = "Top Bigram") +
  theme(
    plot.title = element_text(face = "bold", color = "#2A2A57", hjust = 0.3, size = 20),
    axis.title = element_blank(),
    axis.text.y = element_text(face = "bold")
  ) +
  scale_fill_manual(values = family_guy_Palette)

Sentiment Analysis [TABS]

AFINN

family_afinn <- family_tidy %>% inner_join(get_sentiments("afinn"))
family_afinn %>% 
  count(index, value) %>% 
  group_by(index) %>% 
  summarise(total_value = sum(value * n)) %>% 
  ggplot(aes(index, total_value)) +
  geom_smooth(se = FALSE, color = "purple3") +
  geom_hline(yintercept = 0, linetype = 2, alpha = 0.5, color = "red") +
  labs(
    title = "How does Polarity vary throughout the Series ?",
    y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold", color = "dodgerblue", hjust = 0.5, size = 25),
    axis.title.x = element_text(face = "bold", size = 12)
  )

family_afinn %>% 
  count(season, index, value) %>% 
  group_by(season, index) %>% 
  summarise(total_value = sum(value * n)) %>%
  ungroup() %>% 
  ggplot(aes(index, total_value)) +
  geom_smooth(se = FALSE, color = "purple3") +
  geom_hline(yintercept = 0, linetype = 2, alpha = 0.5, color = "red") +
  facet_wrap(~season, nrow = 4, scales = "free_x") +
  labs(
    title = "By Season ?",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "italic", color = "dodgerblue", hjust = 0.5, size = 20),
    axis.text = element_text(face = "bold"),
    strip.text = element_text(face = "bold", color = "goldenrod", size = 15)
  )

# Peter
gg_afinn_Peter <- family_afinn %>%
  filter(character == "Peter") %>%
  group_by(season, index, character) %>% 
  count(value) %>% 
  summarise(total_value = sum(value * n)) %>%
  ungroup() %>%
  mutate(season = case_when(
    season %in% c(1:3) ~ "Season 1-3",
    season %in% c(4:6) ~ "Season 4-6",
    season %in% c(7:9) ~ "Season 7-9",
    season %in% c(10:12) ~ "Season 10 & 12"
  ) %>% factor(levels = c("Season 1-3","Season 4-6","Season 7-9","Season 10 & 12"))) %>% 
  ggplot(aes(index, total_value)) +
  geom_smooth(se = FALSE, size = 2, color = peter) +
  geom_hline(yintercept = 0, linetype = 2, size = 1,  
             alpha = 0.3, color = "red") +
  facet_wrap(~season, scales = "free_x") +
  ylim(c(-4,2)) +
  labs(
    title = "Peter",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold.italic", hjust = 0.5, size = 15, color = peter),
    axis.text.x = element_blank(),
    strip.text = element_text(color = "darkgoldenrod", size = 12)
  )


# Lois
gg_afinn_Lois <- family_afinn %>%
  filter(character == "Lois") %>%
  group_by(season, index, character) %>% 
  count(value) %>% 
  summarise(total_value = sum(value * n)) %>%
  ungroup() %>%
  mutate(season = case_when(
    season %in% c(1:3) ~ "Season 1-3",
    season %in% c(4:6) ~ "Season 4-6",
    season %in% c(7:9) ~ "Season 7-9",
    season %in% c(10:12) ~ "Season 10 & 12"
  ) %>% factor(levels = c("Season 1-3","Season 4-6","Season 7-9","Season 10 & 12"))) %>% 
  ggplot(aes(index, total_value)) +
  geom_smooth(se = FALSE, size = 2, color = lois) +
  geom_hline(yintercept = 0, linetype = 2, size = 1,  
             alpha = 0.3, color = "red") +
  facet_wrap(~season, scales = "free_x") +
  ylim(c(-4,2)) +
  labs(
    title = "Lois",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold.italic", hjust = 0.5, size = 15, color = lois),
    axis.text.x = element_blank(),
    strip.text = element_text(color = "darkgoldenrod", size = 12)
  )


# Stewie
gg_afinn_Stewie <- family_afinn %>%
  filter(character == "Stewie") %>%
  group_by(season, index, character) %>% 
  count(value) %>% 
  summarise(total_value = sum(value * n)) %>%
  ungroup() %>%
  mutate(season = case_when(
    season %in% c(1:3) ~ "Season 1-3",
    season %in% c(4:6) ~ "Season 4-6",
    season %in% c(7:9) ~ "Season 7-9",
    season %in% c(10:12) ~ "Season 10 & 12"
  ) %>% factor(levels = c("Season 1-3","Season 4-6","Season 7-9","Season 10 & 12"))) %>% 
  ggplot(aes(index, total_value)) +
  geom_smooth(se = FALSE, size = 2, color = stewie) +
  geom_hline(yintercept = 0, linetype = 2, size = 1,  
             alpha = 0.3, color = "red") +
  facet_wrap(~season, scales = "free_x") +
  ylim(c(-4,2)) +
  labs(
    title = "Stewie",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold.italic", hjust = 0.5, size = 15, color = stewie),
    axis.text.x = element_blank(),
    strip.text = element_text(color = "darkgoldenrod", size = 12)
  )


# Brian
gg_afinn_Brian <- family_afinn %>%
  filter(character == "Brian") %>%
  group_by(season, index, character) %>% 
  count(value) %>% 
  summarise(total_value = sum(value * n)) %>%
  ungroup() %>%
mutate(season = case_when(
    season %in% c(1:3) ~ "Season 1-3",
    season %in% c(4:6) ~ "Season 4-6",
    season %in% c(7:9) ~ "Season 7-9",
    season %in% c(10:12) ~ "Season 10 & 12"
  ) %>% factor(levels = c("Season 1-3","Season 4-6","Season 7-9","Season 10 & 12"))) %>% 
  ggplot(aes(index, total_value)) +
  geom_smooth(se = FALSE, size = 2, color = brian) +
  geom_hline(yintercept = 0, linetype = 2, size = 1,  
             alpha = 0.3, color = "red") +
  facet_wrap(~season, scales = "free_x") +
  ylim(c(-4,2)) +
  labs(
    title = "Brian",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold.italic", hjust = 0.5, size = 15, color = brian),
    axis.text.x = element_blank(),
    strip.text = element_text(color = "darkgoldenrod", size = 12)
  )


# Chris
gg_afinn_Chris <- family_afinn %>%
  filter(character == "Chris") %>%
  group_by(season, index, character) %>% 
  count(value) %>% 
  summarise(total_value = sum(value * n)) %>%
  ungroup() %>%
  mutate(season = case_when(
    season %in% c(1:3) ~ "Season 1-3",
    season %in% c(4:6) ~ "Season 4-6",
    season %in% c(7:9) ~ "Season 7-9",
    season %in% c(10:12) ~ "Season 10 & 12"
  ) %>% factor(levels = c("Season 1-3","Season 4-6","Season 7-9","Season 10 & 12"))) %>% 
  ggplot(aes(index, total_value)) +
  geom_smooth(se = FALSE, size = 2, color = chris) +
  geom_hline(yintercept = 0, linetype = 2, size = 1,  
             alpha = 0.3, color = "red") +
  facet_wrap(~season, scales = "free_x") +
  ylim(c(-4,2)) +
  labs(
    title = "Peter",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold.italic", hjust = 0.5, size = 15, color = chris),
    axis.text.x = element_blank(),
    strip.text = element_text(color = "darkgoldenrod", size = 12)
  )


# Meg
gg_afinn_Meg <- family_afinn %>%
  filter(character == "Meg") %>%
  group_by(season, index, character) %>% 
  count(value) %>% 
  summarise(total_value = sum(value * n)) %>%
  ungroup() %>%
  mutate(season = case_when(
    season %in% c(1:3) ~ "Season 1-3",
    season %in% c(4:6) ~ "Season 4-6",
    season %in% c(7:9) ~ "Season 7-9",
    season %in% c(10:12) ~ "Season 10 & 12"
  ) %>% factor(levels = c("Season 1-3","Season 4-6","Season 7-9","Season 10 & 12"))) %>% 
  ggplot(aes(index, total_value)) +
  geom_smooth(se = FALSE, size = 2, color = meg) +
  geom_hline(yintercept = 0, linetype = 2, size = 1,  
             alpha = 0.3, color = "red") +
  facet_wrap(~season, scales = "free_x") +
  ylim(c(-4,2)) +
  labs(
    title = "Meg",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold.italic", hjust = 0.5, size = 15, color = meg),
    axis.text.x = element_blank(),
    strip.text = element_text(color = "darkgoldenrod", size = 12)
  )


# Arrange
ggAR_family_1 <- ggarrange(gg_afinn_Peter, gg_afinn_Stewie, gg_afinn_Chris, nrow = 1)
ggAR_family_2 <- ggarrange(gg_afinn_Lois, gg_afinn_Brian, gg_afinn_Meg, nrow = 1) 
# Visual
ggarrange(ggAR_family_1, ggAR_family_2, ncol = 1) %>% 
  annotate_figure(top = text_grob(label = "By Character ?",
                                  size = 20, face = "italic", color = "dodgerblue"))

BING

family_bing <- family_tidy %>% inner_join(get_sentiments("bing"))
# Count
family_bing %>% count(sentiment) %>% 
  ggplot(aes(sentiment, n, fill = sentiment)) +
  geom_col(show.legend = FALSE, alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  labs(
    title = "What is the Word Count by Sentiment ?",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold", hjust = 0.5, color = "dodgerblue", size = 25),
    axis.text.x = element_text(face = "bold", color = "gray25"),
    axis.text.y = element_blank(),
    legend.position = "none"
  ) +
  scale_fill_manual(values = c("tomato","forestgreen"))

family_bing %>% 
  count(word, sentiment) %>% 
  spread(sentiment, n, fill = 0) %>% 
  mutate(polarity = positive - negative) %>% 
  mutate(pos_neg = ifelse(polarity > 0, "positive","negative")) %>% 
  filter(abs(polarity) >= 8) %>% 
  ggplot(aes(fct_reorder(word, polarity), polarity, fill = pos_neg)) +
  geom_col(show.legend = FALSE, alpha = 0.5) +
  geom_label(aes(label = polarity), color = "white") +
  coord_flip() +
  labs(title = "What are the Top Positive and Negative Words ?",
       x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold", color = "dodgerblue", hjust = 0.5, size = 25),
    plot.subtitle = element_text(color = "darkgoldenrod", hjust = 0.5, size = 15),
    axis.text.x = element_blank(),
    legend.position = "none"
  ) +
  scale_fill_manual(values = c("tomato", "forestgreen"))

family_bing %>% 
  mutate(season = case_when(
    season %in% c(1:3) ~ "Season 1-3",
    season %in% c(4:6) ~ "Season 4-6",
    season %in% c(7:9) ~ "Season 7-9",
    season %in% c(10:12) ~ "Season 10 & 12"
  ) %>% factor(levels = c("Season 1-3","Season 4-6","Season 7-9","Season 10 & 12"))) %>% 
  group_by(season, sentiment) %>% 
  count(word, sort = TRUE) %>%
  top_n(5, n) %>%
  ggplot(aes(n, fct_reorder(word, n), fill = sentiment)) +
  geom_col(show.legend = FALSE, alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~season, scales = "free") +
  labs(
    title = "What are the top Positive and Negative Words by Season ?",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "italic", color = "dodgerblue", hjust = 0.5, size = 20),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", color = "darkgoldenrod", size = 15),
    legend.position = "none"
  ) + scale_fill_manual(values = c("tomato","forestgreen"))

# Total by Character
family_bing %>% 
  group_by(character) %>% 
  count(sentiment) %>% 
  ggplot(aes(sentiment, n, fill = sentiment)) +
  geom_col(show.legend = FALSE, alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~character, nrow = 1) +
  labs(
    title = "What is the count of Positive and Negative Words by Character ?",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold", color = "dodgerblue", hjust = 0.5, size = 25),
    axis.text = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = c("tomato","forestgreen"))

# Character Top Words: Positive
gg_bing_character_Positive <- family_bing %>%
  filter(sentiment == "positive") %>% 
  group_by(character) %>% 
  count(word) %>% 
  top_n(3, n) %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(word, n), fill = character)) +
  geom_col(show.legend = FALSE, alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~ character, scales = "free", nrow = 2) +
  labs(
    x = NULL, y = NULL
  ) +
  theme(
      axis.text.y = element_text(face = "bold", color = "gray35"),
      axis.text.x = element_blank(),
      strip.text = element_text(face = "bold", size = 15, color = "forestgreen"),
      legend.position = "none"
  ) +
  scale_fill_manual(values = family_guy_Palette)

# Character Top Words: Negative
gg_bing_character_Negative <- family_bing %>%
  filter(sentiment == "negative") %>% 
  group_by(character) %>% 
  count(word) %>% 
  top_n(3, n) %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(word, n), fill = character)) +
  geom_col(show.legend = FALSE, alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~ character, scales = "free", nrow = 2) +
  labs(
    x = NULL, y = NULL
  ) +
  theme(
      axis.text.y = element_text(face = "bold", color = "gray35"),
      axis.text.x = element_blank(),
      strip.text = element_text(face = "bold", size = 15, color = "tomato"),
      legend.position = "none"
  ) +
  scale_fill_manual(values = family_guy_Palette)
# Visual
ggAR_bing_character_Polarity <- ggarrange(gg_bing_character_Positive, gg_bing_character_Negative,
                                          ncol = 2)
ggAR_bing_character_Polarity %>% 
  annotate_figure(top = text_grob(label = "What are the Top Words used by each Character by Polarity ?",
                                  face = "italic", size = 20, color = "dodgerblue"))

# Season 1-3
gg_bing_character_word_1_3 <- family_bing %>% 
  filter(season %in% 1:3) %>% 
  group_by(character) %>% 
  count(sentiment, word) %>% 
  top_n(5, n) %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(word, n), fill = sentiment)) +
  geom_col(show.legend = FALSE, alpha = 0.3) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~ character, scales = "free", nrow = 2) +
  labs(
    subtitle = "Season: 1-3",
    x = NULL, y = NULL
  ) +
  theme(
    plot.subtitle = element_text(face = "bold", color = "darkgoldenrod", hjust = 0.5, size = 18),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = c("tomato","forestgreen"))

# Season 4-6
gg_bing_character_word_4_6 <- family_bing %>% 
  filter(season %in% 4:6) %>% 
  group_by(character) %>% 
  count(sentiment, word) %>% 
  top_n(5, n) %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(word, n), fill = sentiment)) +
  geom_col(show.legend = FALSE, alpha = 0.3) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~ character, scales = "free", nrow = 2) +
  labs(
    subtitle = "Season: 4-6",
    x = NULL, y = NULL
  ) +
  theme(
    plot.subtitle = element_text(face = "bold", color = "darkgoldenrod", hjust = 0.5, size = 18),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = c("tomato","forestgreen"))

# Season 7-9
gg_bing_character_word_7_9 <- family_bing %>% 
  filter(season %in% 7:9) %>% 
  group_by(character) %>% 
  count(sentiment, word) %>% 
  top_n(5, n) %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(word, n), fill = sentiment)) +
  geom_col(show.legend = FALSE, alpha = 0.3) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~ character, scales = "free", nrow = 2) +
  labs(
    subtitle = "Season: 7-9",
    x = NULL, y = NULL
  ) +
  theme(
    plot.subtitle = element_text(face = "bold", color = "darkgoldenrod", hjust = 0.5, size = 18),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = c("tomato","forestgreen"))

# Season 10&12
gg_bing_character_word_10_12 <- family_bing %>% 
  filter(season %in% 10:12) %>% 
  group_by(character) %>% 
  count(sentiment, word) %>% 
  top_n(5, n) %>% 
  ungroup() %>% 
  ggplot(aes(n, fct_reorder(word, n), fill = sentiment)) +
  geom_col(show.legend = FALSE, alpha = 0.3) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~ character, scales = "free", nrow = 2) +
  labs(
    subtitle = "Season: 10 & 12",
    x = NULL, y = NULL
  ) +
  theme(
    plot.subtitle = element_text(face = "bold", color = "darkgoldenrod", hjust = 0.5, size = 18),
    axis.text.x = element_blank(),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = c("tomato","forestgreen"))
# Arrange
ggAR_bing_character_word_1_6 <- ggarrange(gg_bing_character_word_1_3, gg_bing_character_word_4_6, nrow = 1)
ggAR_bing_character_word_7_12 <- ggarrange(gg_bing_character_word_7_9, gg_bing_character_word_10_12, nrow = 1)

# Visual
ggarrange(ggAR_bing_character_word_1_6, ggAR_bing_character_word_7_12,
          nrow = 2) %>% 
  annotate_figure(top = text_grob(label = "What are the Top Words used by each Character by Polarity/Season ?",
                                  face = "italic", size = 20, color = "dodgerblue"))

NRC

family_nrc <- family_tidy %>% inner_join(get_sentiments("nrc"))

# color palette
nrc_palette <- c("deeppink","orange","khaki4","magenta4","springgreen3","tomato","forestgreen","slateblue","lightpink","lightblue")
family_nrc %>% 
  count(sentiment) %>% 
  ggplot(aes(sentiment, n, fill = sentiment)) +
  geom_col(alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  labs(
    title = "What is the Word Count by Sentiment ?",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold", hjust = 0.5, color = "dodgerblue", size = 25),
    axis.text.y = element_blank(),
    axis.text.x = element_text(face = "bold", color = "gray50", size = 12),
    legend.position = "none"
  ) +
  scale_fill_manual(values = nrc_palette)

family_nrc %>% 
  group_by(season) %>% 
  count(sentiment) %>% 
  ggplot(aes(sentiment, n, fill = sentiment)) +
  geom_col(alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~season) +
  coord_flip() +
  labs(
    title = "What are the Top Sentiments by Season ?",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "italic", hjust = 0.5, color = "dodgerblue", size = 20),
    axis.text.x = element_blank(),
    axis.text.y = element_text(face = "bold", size = 12, color = "gray50"),
    strip.text = element_text(face = "bold", size = 15, color = "darkgoldenrod"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = nrc_palette)

family_nrc %>% 
  group_by(character) %>% 
  count(sentiment) %>% 
  ggplot(aes(sentiment, n, fill = sentiment)) +
  geom_col(alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~character) +
  coord_flip() +
  labs(
    title = "What are the Top Sentiments by Character ?",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "italic", hjust = 0.5, color = "dodgerblue", size = 20),
    axis.text.x = element_blank(),
    axis.text.y = element_text(face = "bold", size = 12, color = "gray50"),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = nrc_palette)

# Season 1-6
gg_nrc_count_season_1_6 <- family_nrc %>% 
  filter(season %in% 1:6) %>% 
  group_by(character) %>% 
  count(sentiment) %>% 
  ggplot(aes(sentiment, n, fill = sentiment)) +
  geom_col(alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~character) +
  coord_flip() +
  labs(
    subtitle = "Season 1-6",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold", hjust = 0.5, color = "dodgerblue", size = 25),
    plot.subtitle = element_text(color = "darkgoldenrod", hjust = 0.5, size = 15),
    axis.text.x = element_blank(),
    axis.text.y = element_text(face = "bold", size = 12, color = "gray50"),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = nrc_palette)

# Season 7-12
gg_nrc_count_season_7_12 <- family_nrc %>% 
  filter(season %in% 7:12) %>% 
  group_by(character) %>% 
  count(sentiment) %>% 
  ggplot(aes(sentiment, n, fill = sentiment)) +
  geom_col(alpha = 0.5) +
  geom_label(aes(label = n), color = "white") +
  facet_wrap(~character) +
  coord_flip() +
  labs(
    subtitle = "Season 7-12",
    x = NULL, y = NULL
  ) +
  theme(
    plot.title = element_text(face = "bold", hjust = 0.5, color = "dodgerblue", size = 25),
    plot.subtitle = element_text(color = "darkgoldenrod", hjust = 0.5, size = 15),
    axis.text.x = element_blank(),
    axis.text.y = element_text(face = "bold", size = 12, color = "gray50"),
    strip.text = element_text(face = "bold", size = 15, color = "grey35"),
    legend.position = "none"
  ) +
  scale_fill_manual(values = nrc_palette)
# Visual
ggAR_nrc_count_season <- ggarrange(gg_nrc_count_season_1_6, gg_nrc_count_season_7_12, nrow = 1)
ggAR_nrc_count_season %>% 
  annotate_figure(top = text_grob(label = "What are the Top Sentiments by Character ?",
                                  size = 25, color = "dodgerblue"))

Topic Modeling [TABS]

2 Topics

3 Topics

4 Topics

Model Evaluation

tibble(
  document = "Season",
  k = c(2,2,2),
  alpha = c(0,1,3),
  delta = 0.1,
  logLike = c(logLik(lda_Season_2_a0), logLik(lda_Season_2_a1), logLik(lda_Season_2_a3)),
  perplexity = c(perplexity(lda_Season_2_a0, family_dtm_Season),
                 perplexity(lda_Season_2_a1, family_dtm_Season), 
                 perplexity(lda_Season_2_a3, family_dtm_Season))
)
## # A tibble: 3 x 6
##   document     k alpha delta logLike perplexity
##   <chr>    <dbl> <dbl> <dbl>   <dbl>      <dbl>
## 1 Season       2     0   0.1 -40827.      1285.
## 2 Season       2     1   0.1 -40823.      1286.
## 3 Season       2     3   0.1 -40723.      1294.